package org.netEase.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.netEase.dao.recommentDao;
import org.netEase.entity.shangping;
import org.netEase.entity.shoprecomment;
import org.netEase.entity.zhuti;
import org.netEase.util.BaseDao;

public class recommentDaoImple extends BaseDao implements recommentDao {

	@Override
	public List<shoprecomment> listGetBy() {
		String sql = "SELECT s.shop_recId,z.Yid,z.name,sh.Sid,sh.Simg,sh.Sname,sh.Sjiage,s.sr_start_time,s.sr_end_time FROM shop_recomment s INNER JOIN zhuti z ON s.zhutiId=z.Yid INNER JOIN shangping sh ON s.shangpingId=sh.Sid";
		List<shoprecomment> list = new ArrayList<>();
		ResultSet rs = super.executeQuery(sql);
		try {
			while (rs.next()) {
				shoprecomment shoprecomment = new shoprecomment();
				shoprecomment.setShop_recId(rs.getInt("shop_recId"));
				zhuti zhuti = new zhuti();
				zhuti.setName(rs.getString("name"));
				
				zhuti.setYid(rs.getInt("Yid"));
				shoprecomment.setZhuti(zhuti);
				shangping shangping = new shangping();
				shangping.setSid(rs.getInt("sid"));
				shangping.setShopimage(rs.getString("Simg"));
				shangping.setShopname(rs.getString("Sname"));
				shangping.setSjiage(rs.getDouble("Sjiage"));
				shoprecomment.setShangping(shangping);
				shoprecomment.setSr_end_time(rs.getDate("sr_end_time"));
				shoprecomment.setSr_start_time(rs.getDate("sr_start_time"));
				
				list.add(shoprecomment);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	@Override
	public List<shoprecomment> listGetBy(String name) {
		String sql = "SELECT s.shop_recId,z.Yid,z.name,sh.Sid,sh.Simg,sh.Sname,sh.Sjiage,s.sr_start_time,s.sr_end_time FROM shop_recomment s INNER JOIN zhuti z ON s.zhutiId=z.Yid INNER JOIN shangping sh ON s.shangpingId=sh.Sid  where z.name = ?";
		List<shoprecomment> list = new ArrayList<>();
		ResultSet rs = super.executeQuery(sql,name);
		try {
			while (rs.next()) {
				shoprecomment shoprecomment = new shoprecomment();
				shoprecomment.setShop_recId(rs.getInt("shop_recId"));
				zhuti zhuti = new zhuti();
				zhuti.setName(rs.getString("name"));
				
				zhuti.setYid(rs.getInt("Yid"));
				shoprecomment.setZhuti(zhuti);
				shangping shangping = new shangping();
				shangping.setSid(rs.getInt("sid"));
				shangping.setShopimage(rs.getString("Simg"));
				shangping.setShopname(rs.getString("Sname"));
				shangping.setSjiage(rs.getDouble("Sjiage"));
				shoprecomment.setShangping(shangping);
				shoprecomment.setSr_end_time(rs.getDate("sr_end_time"));
				shoprecomment.setSr_start_time(rs.getDate("sr_start_time"));
				
				list.add(shoprecomment);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

}
